package cc.vv.btpartyjob.partymanager.activity

import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import android.view.View
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.adapter.ManagerViewPageAdapter
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.delegate.ZuZhiDynamicDelegate
import cc.vv.btpartyjob.partymanager.fragment.ZuZhiDynamicOneFragment
import cc.vv.btpartyjob.partymanager.fragment.ZuZhiDynamicTwoFragment
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder

/**
 * 组织动态
 * Created by Chen.qi on 2018/10/29.
 */
class ZuZhiDynamicActivity : BaseActivityMVP<ZuZhiDynamicDelegate>() {
    /**
     * ViewPager适配器
     */
    private var mAdapter: ManagerViewPageAdapter? = null

    /**
     * Fragment集合
     */
    private var mFragments: ArrayList<Fragment>? = null

    private var communityId: String? = null

    override fun initData() {
        viewDelegate?.setTopBarTitle("组织动态", false)
        mFragments = ArrayList()
        try {
            communityId = intent.getStringExtra("communityId")
        } catch (e: Exception) {
        }
        val registerYesFragment = ZuZhiDynamicOneFragment()
        registerYesFragment.setOrgId(communityId)
        val registerNoFragment = ZuZhiDynamicTwoFragment()
        registerNoFragment.setOrgId(communityId)
        mFragments!!.add(registerYesFragment)
        mFragments!!.add(registerNoFragment)
        mAdapter = ManagerViewPageAdapter(supportFragmentManager, mFragments!!)
        viewDelegate?.setAdapterData(mAdapter!!)
        viewDelegate?.setEvaluateSelect(true)

    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {

            }
        })

        viewDelegate?.setOnClickListener(View.OnClickListener {
            //社会组织
            viewDelegate?.setEvaluateSelect(true)
            viewDelegate?.setViewPagerPos(0)
        }, R.id.tv_zhDyna_evaluateNo)


        viewDelegate?.setOnClickListener(View.OnClickListener {
            //社会组织动态
            viewDelegate?.setEvaluateSelect(false)
            viewDelegate?.setViewPagerPos(1)
        }, R.id.tv_zhDyna_evaluateYes)

        viewDelegate?.bindViewPagerLisener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {
                if (position == 0) {
                    viewDelegate?.setEvaluateSelect(true)
                } else {
                    viewDelegate?.setEvaluateSelect(false)
                }
            }
        })
    }

    override fun getDelegateClass(): Class<ZuZhiDynamicDelegate> {
        return ZuZhiDynamicDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }
}